package com.bw.module_motorcircle.ui.post.adapter

import android.os.Bundle
import androidx.recyclerview.widget.DiffUtil
import com.bw.module_motorcircle.model.PostItem

/**
 * @author ytx
 * @date 2025-09-25 16:45
 * @description
 */
class PostsDiffCallBack(val oldList:List<PostItem>,val newList:List<PostItem>):DiffUtil.Callback() {
    override fun getOldListSize(): Int {
        return oldList.size
    }

    override fun getNewListSize(): Int {
        return newList.size
    }

    override fun areItemsTheSame(p0: Int, p1: Int): Boolean {
        return oldList[p0].posts_id == newList[p1].posts_id
    }

    override fun areContentsTheSame(p0: Int, p1: Int): Boolean {
        return oldList[p0] == newList[p1] //kotlin ==比较的是内容 ===比较的是地址值   java equals比较的内容 ==比较的地址值
    }
    /**
     * 局部增量刷新：同一个对象，但是内容不一样，局部增量刷新
     */
    override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? {
        val oldUser = oldList[oldItemPosition]
        val newUser = newList[newItemPosition]

        val payload = Bundle()
        if (oldUser.if_like != newUser.if_like) {
            payload.putInt("if_like", newUser.if_like)
        }
        if (oldUser.if_collect != newUser.if_collect) {
            payload.putInt("if_collect", newUser.if_collect)
        }
        //。。。。。。。。。。
        return if (payload.size() > 0) payload else null
    }

}